//
//  MPAuthMultiPartImageRequestParameter.m
//  MPOAuthMobile
//
//  Created by Christopher Anderson on 14/03/2009.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "MPOAuthMultiPartImageRequestParameter.h"


@implementation MPOAuthMultiPartImageRequestParameter

@synthesize name;
@synthesize image;
@synthesize mimeType;

- (id)initWithName:(NSString*)inName image:(UIImage*)inImage mimeType:(NSString*)inMimeType {
	self = [super initWithName:inName];
	if (self) {
		image = inImage;
		mimeType = inMimeType;
	}
	return self;
}

- (NSData*) formPostData {
	NSMutableData *formData = [[NSMutableData alloc] init];
	NSString *contentDisposition = [NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"; filename=\"%@\"\r\n", self.name, self.image];
	[formData appendData:[contentDisposition dataUsingEncoding:NSUTF8StringEncoding]];
	
	NSString *contentType = [NSString stringWithFormat:@"Content-Type: %@\r\n\r\n", self.mimeType];
	[formData appendData:[contentType dataUsingEncoding:NSUTF8StringEncoding]];
	
	[formData appendData:UIImagePNGRepresentation(image)];
	
	//NSString *filePath = [[NSBundle mainBundle] pathForResource:self.image ofType:@"JPG"];  
	//[formData appendData:[NSData dataWithContentsOfFile:filePath]];
	 
	 return formData;
}

@end
